package com.study.guide.pack.splicing.DelimiterBasedFrameDecoder;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

public class TimeClientInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ByteBuf delimiter = Unpooled.copiedBuffer("$_".getBytes());
		ChannelPipeline pl = ch.pipeline(); //连接所有处理器
		pl
//			.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0,4,0,4))
//			.addLast(new LengthFieldPrepender(4))
//			.addLast(new StringDecoder(CharsetUtil.UTF_8))
//			.addLast(new StringEncoder(CharsetUtil.UTF_8))
			.addLast(new DelimiterBasedFrameDecoder(1024,delimiter))
			.addLast(new StringDecoder())
			.addLast(new TimeClientHandler());
	}

}
